@@include('../common.html')
<!-- 管理页需要引入的js -->
<script src="/assets/vendors/nprogress/nprogress.js"></script>
<script src="/assets/vendors/jquery/jquery.js"></script>
<script src="/assets/vendors/bootstrap/js/bootstrap.js"></script>
<script src="/assets/vendors/art-template/template-web.js"></script>

<script>
    // 为全局ajax设置请求头携带 token
    $.ajaxSetup({
        // beforeSend:请求发出之前执行函数
        beforeSend: function (xhr) {
            // 从localtion中获取token
            const token = localStorage.getItem('token')
            // console.log('token:', token);
            xhr.setRequestHeader('Authorization', token)
        },
        timeout: 5000  //请求时间限制
    })
    // 获取用户登录状态
    $.ajax(`${baseUrl}/login/status`, {
        success: function (res) {
            // console.log(res.data);
            if (res.data && res.data.isLogin) {
                // 全局保存 userId
                window.userId = res.data.userId
            } else {
                alert('登录失效！')
                location.href = 'login.html'
            }
        },
        error: function (err) {
            console.log(err);
            alert('登录失效！')
            location.href = 'login.html'
        }
    })

</script>